#include "common.h"
#include "Lexer.h"
#include "SyntaxTree.h"
#include <vector>

class Parser {
private:
	Lexer *lexer;
	Token currentToken;
	std::vector<SyntaxTree*> trees;
	bool isPrimary;
    int flag; // if flag == 1, that is current tree cannot be
              // forwarded.

	Token nextToken();

	void Statement();
	SyntaxTree* Create();
	SyntaxTree* Insert();
	SyntaxTree* Delete();
	SyntaxTree* Query();
	SyntaxTree* decl_list();
	SyntaxTree* decl();
	SyntaxTree* default_spec();
	SyntaxTree* column_list();
	SyntaxTree* conjunct_list();
	SyntaxTree* where_clause();
	SyntaxTree* boolean();
	SyntaxTree* operand();
	SyntaxTree* rop();
	SyntaxTree* value_list();
	SyntaxTree* select_list();
	numNode* simple_expr();
	numNode* simple_term();
	numNode* simple_unary();
	numNode* simple_partner();
	numNode* simple_atom();
	
	SyntaxTree* disjunct();
	SyntaxTree* conjunct();
	SyntaxTree* bool_partner();
	SyntaxTree* comp();
	SyntaxTree* expr();
	SyntaxTree* term();
	SyntaxTree* unary();
	SyntaxTree* partner();
	SyntaxTree* atom();

	inline bool isRop();
	void printError(const char *error);

public:
	Parser(char* sourcefile);
	Parser();
	~Parser();

	void reset();
	void printError();
	void parse();
	void setLexer(Lexer *srclexer);
	
	std::vector<SyntaxTree*> getTrees();
};
